<?php

namespace App\Jobs;

use App\Models\V1\LiveMsgFailModel;
use App\Models\V1\LiveMsgModel;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class StoreMsg implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;


    public $tries = 3;
//    public    $delay   = 1;
    public    $timeout = 2;
    protected $data;

    /**
     * Create a new job instance.
     *
     * @param $data
     */
    public function __construct(array $data)
    {

        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $data = $this->data;
        LiveMsgModel::create([
            'user_name'  => $data['user_name'],
            'body'       => $data['body'],
            'avg'        => change_member_head_img($data['avg']),
            'account'    => $data['account'],
            'is_teacher' => $data['is_teacher'],
            'msg'        => $data['msg'],
            'group_id'   => $data['group_id'],
            'msg_seq'    => $data['msg_seq']
        ]);

    }

    public function fail(Exception $exception)
    {
        LiveMsgFailModel::create([
            'message' => '22',
            'code'    => '404',
            'file'    => '404',
            'line'    => '404'
        ]);
    }
}
